﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Yatagan.Library;

namespace Yatagan.IoC.ObjectBuilder
{
    internal class CloneCreator : BaseObjectCreator
    {
        private static Dictionary<Type, object> _objects = new Dictionary<Type, object>();

        internal override object Create(Type type)
        {
            try
            {
                return ObjectCloner.CloneIt((from v in _objects
                        where v.Key == type
                        select v).First().Value);
            }
            catch (Exception)
            {
                NewCreator newCreator = new NewCreator();
                _objects[type] = newCreator.Create(type);
                return ObjectCloner.CloneIt(_objects[type]);
            }
        }
    }
}
